import request from '@/api/request'

const auth = {
  username: 'rcepmkt',
  password: '123456',
}

export const postLogin = (data) => {
  return request({
    url: '/mauth/api/member/login',
    method: 'POST',
    auth,
    data,
  })
}

export const postRegister = (data) => {
  return request({
    url: '/member/api/member/register',
    method: 'POST',
    auth,
    data,
  })
}

// 发送手机验证码
export const sendSmsCode = ({ mobile }) => {
  return request({
    url: '/smsemail/api/sms/send',
    method: 'post',
    params: { mobile },
  })
}

// 发送邮箱验证码
export const sendEmailCode = (data) => {
  return request({
    url: '/smsemail/api/email/sendRegisterCode',
    method: 'get',
    data,
  })
}

// 刷新令牌
export const refreshToken = (token) => {
  return request({
    url: '/mauth/member/refreshToken',
    method: 'get',
    params: { refreshToken: token },
  })
}

// 获取所有地址
export const getAllAddress = () => {
  return request({
    url: '/order/address/search',
    method: 'POST',
  })
}

// 新增、编辑地址
export function PostPutOrderAddress(method, data) {
  return request({
    url: '/order/address',
    method,
    data,
  })
}

// 修改默认地址
export function PutOrderAddressDefault(id) {
  return request({
    url: `/order/address/default/${id}`,
    method: 'POST',
  })
}

// 获取默认地址
export function GetOrderAddressDefault() {
  return request({
    url: '/order/address/default',
    method: 'GET',
  })
}

// 删除地址
export function DeleteAddress(id) {
  return request({
    url: `/order/address/${id}`,
    method: 'DELETE',
  })
}

// 查询当前所有模块信息
export const getAllModule = () =>
  request({
    url: `/member/api/buy/module/search`,
  })

// 查询当前用户开通模块情况
export const getUserAllModule = () =>
  request({
    url: `/member/buy/module/buyModule`,
  })
